package com.spzx.product.service.impl;

import com.spzx.common.core.utils.StringUtils;
import com.spzx.product.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * projectName: spzx-parent
 *
 * @author: 比丢比丢
 * time: 2024/7/17 16:47 周三
 * description:
 */
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void testLock() {

        //1.从redis中获取数据
        String value = (String)stringRedisTemplate.opsForValue().get("num");

        //2.判断
        if(StringUtils.isBlank(value)){
            return;
        }

        int num = Integer.parseInt(value);

        //把value值=1
        stringRedisTemplate.opsForValue().set("num",String.valueOf(++num));
    }
}
